<template>
    <nav class="navbar navbar-expand-lg bg-body-tertiary nb">
        <div class="container">
            <span class="navbar-brand">SQL学习系统</span>
            <div class="collapse navbar-collapse" id="navbarText">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                <li class="nav-item">
                <router-link class="nav-link" aria-current="page" :to="{name: 'classManage'}">班级管理</router-link>
                </li>
                <li class="nav-item">
                <router-link class="nav-link" :to="{name: 'setManage'}">题目管理</router-link>
                </li>
                <li class="nav-item">
                <router-link class="nav-link" :to="{name: 'defaultTable'}">系统默认表</router-link>
                </li>
                <!-- <li class="nav-item">
                <a class="nav-link" href="#">其他</a>
                </li> -->
            </ul>
            <div>
                 <span class="navbar-brand" style="margin-right: 60px; font-weight: bold; font-size: 20px; color:yellowgreen">{{ now }}</span>
            </div>
            <span class="navbar-brand wel">欢迎登录，{{ $store.state.user.username }}老师</span>
            <ul class="navbar-nav">
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        教师信息
                    </a>
                    <ul class="dropdown-menu">
                    <!-- <li><a class="dropdown-item" href="#">我的信息</a></li> -->
                        <li><span class="dropdown-item" href="#">{{ $store.state.user.username }}</span></li>
                        <li><router-link class="dropdown-item" :to="{name: 'login'}" @click="logout">退出登录</router-link></li>
                    </ul>
                </li>
            </ul>
            </div>
        </div>
    </nav>
</template>
   
<script>
   
  import {useStore} from 'vuex'; 
  import {ref} from 'vue';
  import  formateDate from '@/utils/GetCurrentTime';

  export default{
        name : "NavBar",
        setup(){
          const store = useStore();
          let now = ref('');

          const getTime = (now) =>{

            setInterval(() => {
              now.value = formateDate(new Date());
            },1000);

          };

          const logout = () =>{
            store.dispatch("logout");
          };

          getTime(now);

          

          return {
            getTime,
            logout,
            now,
          }
        }
  }
</script>

   
<style scoped>
   a{
      text-decoration: none;
   }
   .nb{
      background-color: #ff070721;
   }
   .wel{
    margin-right:30px;
   }
</style>